package com.javasm.bootdemo.user.controller;

import com.github.pagehelper.PageInfo;
import com.javasm.bootdemo.common.R;
import com.javasm.bootdemo.common.exception.JavasmException;
import com.javasm.bootdemo.common.exception.JavasmExceptionEnum;
import com.javasm.bootdemo.user.entity.WebUserInfo;
import com.javasm.bootdemo.user.service.WebUserInfoService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 陪玩用户表(WebUserInfo)表控制层
 *
 * @author makejava
 * @since 2025-06-25 17:40:46
 */
@RestController
@RequestMapping("/user/info")
public class WebUserInfoController {
    /**
     * 服务对象
     */
    @Resource
    private WebUserInfoService webUserInfoService;

    @GetMapping("/query/{id}")
    public  R  queryById(@PathVariable Integer  id){
        WebUserInfo webUserInfo = webUserInfoService.queryById(id);
        if(id == null){
            throw new JavasmException(JavasmExceptionEnum.ParameterNull);
        }
        return  R.ok(webUserInfo);
    }


    @GetMapping("/list")
    public R list(){
        List<WebUserInfo> list = webUserInfoService.list();

       return R.ok(list);
    }

    @PostMapping("/save")
    public R save(@RequestBody  WebUserInfo webUserInfo){
        if(webUserInfo == null){
            throw  new JavasmException(JavasmExceptionEnum.ParameterNull);
        }
        webUserInfoService.insert(webUserInfo);
        return  R.ok(webUserInfo);
    }

    @PutMapping("/upupup")
    public R update(@RequestBody WebUserInfo webUserInfo){
        if(webUserInfo ==  null && webUserInfo.getUid() == null){
            throw new JavasmException(JavasmExceptionEnum.ParameterNull);
        }
        WebUserInfo info = webUserInfoService.update(webUserInfo);
        return  R.ok(info);


    }


    @DeleteMapping("/{uid}")
    public  R  deleteById(@PathVariable Integer uid){
        webUserInfoService.deleteById(uid);
        return R.ok();
    }
@GetMapping("/page")
    public R listByPage(Integer  pageSize,Integer pageNum){
        PageInfo<WebUserInfo> pageInfo = webUserInfoService.listPage(pageSize,pageNum);
        return  R.ok(pageInfo);
    }
}

